package com.xjrsoft.module.customer.erp_model.erp_inventoryManage.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.core.mp.base.BaseService;
import com.xjrsoft.core.tool.utils.StringPool;
import com.xjrsoft.core.tool.utils.StringUtil;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.dto.ErpInventoryListDto;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.entity.ErpInventory;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.mapper.ErpInventoryMapper;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.service.IErpInventoryService;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.vo.ErpInventoryListVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  服务实现类
 *
 * @author pp
 * @since 2021-10-19
 */
@Service
@AllArgsConstructor
public class ErpInventoryServiceImpl extends BaseService<ErpInventoryMapper, ErpInventory> implements IErpInventoryService {

	@Override
	public PageOutput<ErpInventoryListVo> getPageList(ErpInventoryListDto pageListDto) {
		IPage<ErpInventoryListVo> page = ConventPage.getPage(pageListDto);
		String goodsName = pageListDto.getF_GoodsName();
		if (!StringUtil.isEmpty(goodsName)) {
			goodsName = StringPool.PERCENT + goodsName + StringPool.PERCENT;
		}
		List<ErpInventoryListVo> erpInventoryVoList = this.baseMapper.getListInfo(pageListDto.getF_GoodsId(), pageListDto.getF_WarehouseId(),
				goodsName, pageListDto.getF_WarehouseName(), page);
		return ConventPage.getPageOutput(page.getTotal(), erpInventoryVoList);
	}
//
//	public List<ErpInventoryVo> getListInfo()
//	{
//		List<ErpInventoryVo> listInfo = this.baseMapper.getListInfo();
//		return listInfo;
//	}

	@Override
	public String addErpInventory(ErpInventory erpInventory) {
		String erpInventoryId = IdWorker.get32UUID();
		erpInventory.setFId(erpInventoryId);
		boolean isSuccess = this.save(erpInventory);
		return isSuccess ? erpInventoryId : null;
	}

	@Override
	public boolean updateErpInventory(String id, ErpInventory erpInventory) {
		erpInventory.setFId(id);
		return this.updateById(erpInventory);
	}

}
